<template>
  <div class="app_wapper">
    <el-container>
      <!-- 左侧菜单 -->
      <el-aside class="slider_container">
        <el-menu class="sub_meuns_wapper" mode="vertical" unique-opened :default-active="$route.path" background-color="#304156" text-color="#fff" active-text-color="#409EFF">
          <!-- 菜单组件 -->
          <side-Menu :routes="getRoutes"></side-Menu>
        </el-menu>
      </el-aside>

      <!-- 右侧内容区域 -->
      <el-container class="app_content">
        <!-- header -->
        <el-header style="text-align: right; font-size: 12px">
          <div style="float: left; font-size: 25px; color: white; font-weight: bold">Qiuの杂货铺</div>
          <div style="float: right">
            <span>{{ username }}</span>
            <i class="el-icon-setting" style="margin: 0 15px"></i>
            <el-button @click="loginOut" size="mini" plain type="primary">退出</el-button>
          </div>
          <div style="height: 60px; width: 60px; float: right; padding: 10px; box-sizing: border-box">
            <img :src="avatar" style="height: 100%; width: 100%; padding: 0; border-radius: 50%; margin: 0; max-width: 100%; background-color: transparent; object-fit: cover" />
          </div>
        </el-header>
        <!-- 内容区域 -->
        <el-main>
          <!-- 二级路由跳转 -->
          <router-view />
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>
<script>
// 左侧菜单组件
import SideMenu from '@/components/SideMenu'
export default {
  computed: {
    getRoutes() {
      return global.antRouter
    }
  },
  components: {
    SideMenu
  },
  data() {
    return {
      avatar: '',
      username: ''
    }
  },
  created() {
    this.avatar = JSON.parse(localStorage.getItem('userInfo')).avatar
    this.username = JSON.parse(localStorage.getItem('userInfo')).username
  },
  methods: {
    loginOut() {
      //退出系统
      localStorage.setItem('token', '')
      // 跳转到登录页的时候顺便刷新
      window.location.href = window.location.origin + window.location.pathname
    }
  }
}
</script>
<style scoped>
/*wapper*/
.app_wapper {
  position: relative;
  height: 100%;
  width: 100%;
}

.el-container {
  height: 100%;
  flex-wrap: nowrap;
  justify-content: flex-start;
  align-items: center;
}

.app_wapper .el-aside,
.slider_container .el-menu {
  color: #333;
  transition: width 0.28s;
  width: 180px !important;
  height: 100%;
  z-index: 1001;
  overflow: hidden;
  background-color: rgb(48, 65, 86);
}

.app_content {
  height: 100%;
  width: calc(100% - 180px);
  border: 1px solid #eee;
  box-sizing: border-box;
}

.el-header {
  background-color: #b3c0d1;
  color: #333;
  line-height: 60px;
  width: 100%;
  padding: 0 10px;
}

.el-main {
  width: 100%;
  height: 100%;
  padding: 10px;
}
</style>
